'''
Created on 2017-6-22

@author: 24253
'''
import pygal
from test import app
from flask import Flask
import pygal_maps_world

test_list = {
'get': u'get an usable proxy',
'refresh': u'refresh proxy pool',
'get_all': u'get all proxy from proxy pool',
' worldmap':u'get all contries'

}

@app.route('/get/')
def get():
    line_chart = pygal.Line()
    line_chart.title = 'xiaorui.cc'
    line_chart.x_labels = ['2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012']
    line_chart.add('Firefox', [1, 2, 0, 16.6,   25,   31, 36.4, 45.5, 46.3, 42.8, 37.1])
    line_chart.add('Chrome',  [3, 2, 5, 77, 43, 22,    0,  3.9, 10.8, 23.8, 35.3])
    line_chart.add('IE',      [85.8, 84.6, 84.7, 74.5,   66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1])
    line_chart.add('Others',  [14.2, 15.4, 15.3,  8.9,    9, 10.4,  8.9,  5.8,  6.7,  6.8,  7.5])
    return line_chart.render()

@app.route('/refresh/')
def refresh():
    line_chart = pygal.StackedLine(fill=True)
    line_chart.title = 'xiaorui.cc'
    line_chart.x_labels = ['2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012']
    line_chart.add('Firefox', [1, 2, 0, 16.6,   25,   31, 36.4, 45.5, 46.3, 42.8, 37.1])
    line_chart.add('Chrome',  [3, 2, 5, 77, 43, 22,    0,  3.9, 10.8, 23.8, 35.3])
    line_chart.add('IE',      [85.8, 84.6, 84.7, 74.5,   66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1])
    line_chart.add('Others',  [14.2, 15.4, 15.3,  8.9,    9, 10.4,  8.9,  5.8,  6.7,  6.8,  7.5])
    return line_chart.render()
 
@app.route('/get_all/')  
def get_all():   
    pie_chart = pygal.Pie()
    pie_chart.title = 'xiaorui.cc'
    pie_chart.add('IE', 19.5)
    pie_chart.add('Firefox', 36.6)
    pie_chart.add('Chrome', 36.3)
    pie_chart.add('Safari', 4.5)
    pie_chart.add('Opera', 2.3)
    return pie_chart.render()

@app.route('/worldmap/')  
def worldmap():
    worldmap_chart = pygal.maps.world.World()
    worldmap_chart.title = 'Some countries'
    worldmap_chart.add('F countries', ['fr', 'fi'])
    worldmap_chart.add('M countries', ['ma', 'mc', 'md', 'me', 'mg',
                               'mk', 'ml', 'mm', 'mn', 'mo',
                               'mr', 'mt', 'mu', 'mv', 'mw',
                               'mx', 'my', 'mz'])
    worldmap_chart.add('U countries', ['ua', 'ug', 'us', 'uy', 'uz'])
    return worldmap_chart.render()

def run():
    app.run(host='0.0.0.0', port=5000) 
if __name__=="__main__":
    run()
    